import {Component, Input, OnInit} from '@angular/core';
import {AlertService} from "../../../../services/alert.service";
import {AdminService} from "../../../../services/admin.service";
import {Prohouseid} from "../../../../model/Prohouseid";
import {AuthService} from "../../../../services/auth.service";

@Component({
  selector: 'app-cprkedit',
  templateUrl: './cprkedit.component.html',
  styleUrls: ['./cprkedit.component.css']
})
export class CprkeditComponent implements OnInit {

  @Input() id: string
  p: Prohouseid
  sjryArray: Array<any>
  ckglyArray: Array<any>

  constructor(private adminService: AdminService,
              private alertService: AlertService,
              private authService:AuthService) {
    this.p = new Prohouseid()
    this.sjryArray = new Array()
    this.ckglyArray = new Array()
  }

  ngOnInit(): void {
    this.getProhouseidByid()
    this.getsjryArray()
    this.getckglyArray()
  }


  getProhouseidByid() {
    this.adminService.getProhouseidByid(this.id).then((data: any) => {
      if (data.msg == "ok") {
        this.p = data.obj

      } else {
        this.alertService.showError("查询入库信息失败")
      }
    })
  }

  save() {
    this.adminService.saveProhouseid(this.p).then((data: any) => {
      if (data.msg == "ok") {
        this.alertService.showSuccess("设置入库信息成功")
      } else {
        this.alertService.showError("设置入库信息失败")
      }
    })
  }

  getckglyArray(){
    this.adminService.getReferdataSelectByTypeid("0cc95ca9badb432384968390e265ab1d").then((data:any)=>{
      if(data.msg == "ok"){
        this.ckglyArray = data.list
      }else{
        this.alertService.showError("获取仓库管理员数组失败")
      }
    })
  }
  getsjryArray(){
    this.authService.getMemberListByRole("11988d2da3984556b02266ca1bdf14f8").then((data:any)=>{
      if(data.msg == "ok"){
        this.sjryArray = data.list
      }else{
        this.alertService.showError("获取送交人员数组失败")
      }
    })
  }
}
